﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Battleborn.Core.Server;
using Microsoft.AspNet.SignalR;

namespace Battleborn.Website.Hubs
{
    public class Battle : Hub
    {
        private int _groupCount;

        public Task Join()
        {
            if (UserHandler.ConnectedIds.Count < 2)
            {
                UserHandler.ConnectedIds.Add(Context.ConnectionId);
                return Groups.Add(Context.ConnectionId, "foo");
            }
            else
            {
                return Groups.Add(Context.ConnectionId, "foo");
            }
        }

        public Task Send(string message)
        {
            return Clients.Group("foo").addMessage(message);
        }

        public override Task OnConnected()
        {
            return Clients.All.joined(Context.ConnectionId, DateTime.Now.ToString());
        }

        public override Task OnDisconnected()
        {
            return Clients.All.leave(Context.ConnectionId, DateTime.Now.ToString());
        }

        public override Task OnReconnected()
        {
            return Clients.All.rejoined(Context.ConnectionId, DateTime.Now.ToString());
        }
    }
}